<%
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1054: By Oscar Bai  Date:2003/02
//   Inactive date and pass_exp_date date formate old:MMDDYYYY new DD/MM/YYYY
//   and add Check date validation

//CR log no 1364: By Beyes Xia  Date:2004/10/22
//   get system parameter to control the minimum length of password
//	 and add Check minimum length of password 
//******************************************************************/
/*--------------------------------------------------------------
 * Modification History
 *--------------------------------------------------------------
 * CRLOG	: CR1528
 * Fix		: Add Company Code
 * By		: PH, HPMS
 * Date		: 06-Dec-2005
 *--------------------------------------------------------------
 */
%>

<%@ include file="../header.jsp"   %>
<%@ page import="admin.*" %>
<%@ page import="admin.options.*" %>

<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>

<!-- Begin of CRLog 1364 -->
<%
	int password_length = (new PasswordLength()).getPasswordLength();
%>
<!-- End of CRLog 1364 -->

<%
    UserBean user1 = (UserBean)request.getAttribute("user");
    if (user1==null)
       user1 = new User();

    RoleOptions rio = new RoleOptions();
  
  //CR log no   begin of : create new CostCenterOption

    CostCenterOptions cco=  new CostCenterOptions();

  //CR log no   end of

//Add by Poly Li,on 2004-02-16------------
	
	UserMultiRoleBean[] userMultiRoles = (UserMultiRoleBean[])request.getAttribute("userMultiRoles");
	String multiRoleId[] = null;
	if (userMultiRoles != null )
	{
		multiRoleId = new String[userMultiRoles.length];
		for(int i = 0; i < userMultiRoles.length; i ++)
			multiRoleId[i] = userMultiRoles[i].getRole_id();
	}
	
//End add by Poly.-------------------------------
%>

<body>
<script language=javascript>

 function formValidation() {
    var d1 = fm.user_id;
    var d2 = fm.user_name;
    var d3 = fm.passwd;
    var d4 = fm.cost_center_id;
    var d5 = fm.staff_id;
    var d6 = fm.pass_exp_date;
    var d7 = fm.inactive_date;
    var d8 = fm.role_id;

    if (isNull(d1,"User ID")||isNull(d2,"User Name")||isNull(d3,"Password")||
    	isNull(d4,"Cost Center ID")||isNull(d5,"Staff ID")||isNull(d8,"Role Id"))
    {
       return false;
    }

    if (d6.value!=""){
      if (!validationDate(d6.value))
      {
        alert("invalid Password Expiry Date!");
        return false;
      }
    }

    if (d7.value!=""){
      if (!validationDate(d7.value))
      {
        alert("invalid Inactive Date!");
        return false;
      }
    }

// Begin of CRLog 1364    
    if(d3.value.length<<%=password_length%>)
    {
    	alert("Password length cannot be less than "+<%=password_length%>);
    	d3.focus();
    	return false;
    }
// End of CRLog 1364    

    return true;
 }

/* CR1054 this function has been moved to header.jsp
 function validationDate(dateStr) {

    var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
    var matchArray = dateStr.match(datePat);

    if (matchArray == null) {
        return false;
    }

    day = matchArray[1];
    month = matchArray[3];
    year = matchArray[5];

    if (day < 1 || day > 31) {
        return false;
    }

    if (month < 1 || month > 12) {
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        return false;
    }

    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            return false;
        }
    }
    return true;
 }
*/

</script>

<h2>User Maintenance</h2>
<form id=fm method=post action=<%=contextPath%>/servlet/admin.UserServlet >
<input type=hidden name=formAction value=<%=formAction%> >
<table cols=10 border=0 >
<tr>
  <td>User ID</td>
  <td><input type=text name=user_id value="<%=user1.getUser_id()%>" maxlength=10 <%=readOnly%> ></td>
</tr>
<tr>
  <td>User Name</td>
  <td><input type=text name=user_name value="<%=user1.getUser_name()%>" maxlength=50></td>
</tr>
<tr>
  <td>User Description</td>
  <td><input type=text name=user_des value="<%=user1.getUser_des()%>" maxlength=100></td>
</tr>
<tr>
  <td>Password</td>

<!-- //CR log no 1054: set pass word, and judge the pass word is changed -->

  <input type=hidden name=oldpasswd value=<%=user1.getPasswd()%>>

<!--//CR log no 1054 end of-->  

  <td><input type=password name=passwd value=<%=user1.getPasswd()%> maxlength=10></td>
</tr>

<tr>
  <td>Password Expiry Date (DD/MM/YYYY)</td>
  <td><input type=text name=pass_exp_date value="<%=user1.getPass_exp_date()%>" maxlength=10></td>
</tr>

<!----------Modified by Poly  2004-4-1 15:55---->
<tr>
  <td>Role ID</td>
  <td>
<%	if (userMultiRoles != null ){	%>
	<select name=role_id size=10 multiple>
		<%=rio.getMultiOptions(multiRoleId)%>
	</select>
<%	}else{	%>
	<select name=role_id size=10 multiple>
		<%=rio.getSingleOptions(user1.getRole_id())%>
	</select>
<%	}	%>
  </td>
</tr>
<!----------End modified by Poly  2004-4-1 15:55---->

<!--
  //CR log no   : set new CostCenterOption for cost center 
   
<tr>
  <td>Cost Center ID</td>
  <td><input type=text name=cost_center_id value="<%=user1.getCost_center_id()%>" maxlength=4></td>
</tr>
-->

<tr>
  <td>Cost Center ID</td>
  <td><select name=cost_center_id><%=cco.getOptions(user1.getCost_center_id())%>>
      </select>
  </td>
</tr>

<tr>
  <td>Email Address</td>
  <td><input type=text name=email value="<%=user1.getEmail()%>" maxlength=50></td>
</tr>

<tr>
  <td>Mobile</td>
  <td><input type=text name=mobile value="<%=user1.getMobile()%>" maxlength=30></td>
</tr>

<tr>
  <td>Staff ID</td>
  <td><input type=text name=staff_id value="<%=user1.getStaff_id()%>" maxlength=15></td>
</tr>

<!-- //CR log no 1054: add field Inactive, and set old_inactive_date 
     //judge the inactive_date field is changed -->

<tr>
  <td>Inactive Date(DD/MM/YYYY)</td>
  <input type=hidden name=old_inactive_date value=<%=user1.getInactive_date()%>>
  <td><input type=text name=inactive_date value="<%=user1.getInactive_date()%>" maxlength=10></td>
</tr>

<!-- //CR log no 1054: -->

<!--// CR Log #: 1055   DATE: Jun 2003   BY: MLin
    // CR Description: To enable multi-company and JIS migration for SRS -->

<tr>
  <td>Request Group</td>
  <td><input type=text name=request_group value="<%=user1.getRequest_group()%>" maxlength=10></td>
</tr>

<!-- End of CRLog 1055 -->
<%/* CR1528 */%>
<tr>
  <td>Company Code</td>
  <td><input type=text name=company_code value="<%=user1.getCompany_code()%>" maxlength=2></td>

</tr>
<tr>
  <td>Login Trial</td>
  <td><input type=text name=login_trial value="<%=user1.getLogin_trial()%>" maxlength=1></td>

</tr>
<%/* CR1528 */%>

</table>
<hr>
<p>
  <INPUT type=button value=Save onclick="save()" >
  <INPUT type=button value=Delete  onclick="deleteRecord()"  >
  <INPUT type=reset  value=Cancel >
</p>
</form>
<%@ include file="../footer.jsp" %>
</body>
</body>
</html>

